{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**1. 编写程序找出$[2000, 3200]$中能被7整除且不能被5整除的所有整数，并以逗号分隔输出成一行。**\n",
    "\n",
    ">**提示：**可以考虑使用`range(#begin, #end)`方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199,\b\n"
     ]
    }
   ],
   "source": [
    "for i in range(2000,3201):\n",
    "    if i%7==0 and i%5!=0:\n",
    "        print(i,end=',')\n",
    "print(\"\\b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**2. 对于输入的整数`n`，采用递归方式编写程序计算`n`的阶乘并输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "8\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "40320\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "40320\n"
     ]
    }
   ],
   "source": [
    "def dd(x):\n",
    "    if x==1: \n",
    "        return 1\n",
    "    else :\n",
    "        return x*dd(x-1)\n",
    "n=int(input())\n",
    "ans=dd(n)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**3. 对于输入的整数`n`，生成一个包含`(i, i*i)`的字典，其中`i`是区间$[1, n]$内的整数，然后输出字典。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "8\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n"
     ]
    }
   ],
   "source": [
    "n=eval(input())\n",
    "l={}\n",
    "for i in range(1,n+1):\n",
    "    l[i]=i*i\n",
    "print(l)\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**4. 对于输入的一个用逗号分隔的数字序列，生成包含每个数字的列表和元组并输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。`tuple()`方法可用来将列表转换为元组。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "34,67,55,33,12,98\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "['34'，'67'，'55'，'33'，'12'，'98']\n",
    "('34'，'67'，'55'，'33'，'12'，'98')\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "34,67,55,33,12,98\n",
      "[34, 67, 55, 33, 12, 98]\n",
      "(34, 67, 55, 33, 12, 98)\n"
     ]
    }
   ],
   "source": [
    "l=[]\n",
    "l=eval(input())\n",
    "print(list(l))\n",
    "print(tuple(l))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5. 定义一个名为`InOutString`的类，该类至少包含两个方法`getString`：从控制台输入获得一个字符串；`printString`：以大写字母方式打印字符串。**\n",
    "\n",
    "> **提示：**\n",
    "* 可以使用`init`方法来构造一些参数；\n",
    "* 除了完成类的定义外，还需要编写简单的测试函数来验证上述类方法的有效性，并给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "Listeria monocytogenes\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "LISTERIA MONOCYTOGENES\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Listeria monocytogenes\n",
      "LISTERIA MONOCYTOGENES\n"
     ]
    }
   ],
   "source": [
    "class InOutString:\n",
    "    def __init__(self,str):\n",
    "        self.str=str\n",
    "    def getString(self):\n",
    "        pass\n",
    "    def printString(self):\n",
    "        print(self.str.upper())\n",
    "       \n",
    "s=input()\n",
    "hh=InOutString(s)\n",
    "hh.getString()\n",
    "hh.printString()\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**6. 已知`Q`是`2 * C * D / H`的平方根，编写程序计算并输出`Q`的值，其中`C`和`H`是常量，它们的值分别为`50`和`30`。`D`是变量，它的值是一个输入的用逗号分隔的整数序列。**\n",
    "\n",
    ">**提示：**如果输出的`Q`值是小数，四舍五入处理为整数，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "100,150,180\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "18,22,24\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100,150,180\n",
      "[18, 22, 24]\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "d=[]\n",
    "d=eval(input())\n",
    "q=[]\n",
    "for i in range(0,3):\n",
    "    x=math.sqrt((2*50*d[i])/30)\n",
    "    q.append(round(x))\n",
    "print(q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**7. 输入`X`和`Y`两个整数，用逗号分隔，生成一个2维数组，数组的第`i`行`j`列的元素值为`i*j`。**\n",
    "\n",
    ">**提示：**`i=0,1,...,X-1`，`j=0,1,...,Y-1`。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "3,5\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3,5\n",
      "[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]\n"
     ]
    }
   ],
   "source": [
    "x,y=eval(input())\n",
    "ls=[]\n",
    "for i in range(x):\n",
    "    fi=[]\n",
    "    for j in range(y):\n",
    "        fi.append(j*i)\n",
    "    ls.append(fi)\n",
    "print(ls)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**8. 输入逗号分隔的单词序列，对这些单词按字母进行排序，然后再以逗号分隔的形式输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "without,hello,bag,world\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "bag,hello,without,world\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "without,hello,bag,world\n",
      "['bag', 'hello', 'without', 'world']\n"
     ]
    }
   ],
   "source": [
    "l=input().split(',')\n",
    "l.sort()\n",
    "print(l)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**9. 输入多行字符串，将每一行的字符变为大写，然后按行输出。**\n",
    "\n",
    ">**提示：**可以使用`input()`方法搭配`while`循环实现多行字符串输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "Hello\n",
    "world\n",
    "Practice\n",
    "makes\n",
    "perfect\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "HELLO\n",
    "WORLD\n",
    "PRACTICE\n",
    "MAKES\n",
    "PERFECT\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "dsdsda\n",
      "www\n",
      "end\n",
      "HELLO\n",
      "DSDSDA\n",
      "WWW\n"
     ]
    }
   ],
   "source": [
    "end='end'\n",
    "l=[]\n",
    "for i in iter(input,end):\n",
    "    l.append(i.upper())\n",
    "for i in l:\n",
    "    print(i,end=\"\\n\")\n",
    " \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**10. 输入一个由空格分隔的单词序列，将重复的单词去掉，并且按照字母数字顺序进行排序后输出。**\n",
    "\n",
    ">**提示：**\n",
    "* 使用`set`来自动去重；\n",
    "* 使用`sorted()`方法来实现排序。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "hello world and practice makes perfect and hello world again\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "again and hello makes perfect practice world\n",
    "```\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world and practice makes perfect and hello world again\n",
      "again and hello makes perfect practice world "
     ]
    }
   ],
   "source": [
    "n=input().split(' ')\n",
    "x=list(set(n))\n",
    "x.sort()\n",
    "for i in x:\n",
    "    print(i,end=\" \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**11. 输入一个由逗号分隔的4位二进制数序列，请判断它们是否能被5整除。输出能被5整除的数，并用逗号分隔。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "0100,0011,1010,1001\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "1010\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0100,0011,1010,1001\n",
      "1010\n"
     ]
    }
   ],
   "source": [
    "l=input().split(',')\n",
    "for i in l:\n",
    "    if int(i,2)%5==0:\n",
    "        print(i,end=',')\n",
    "print(\"\\b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**12. 请在$[1000,3000]$区间内的整数中，编程找出那些每个数位都是偶数的整数，采用单行逗号分隔的形式输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'str' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9836/3212207544.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1000\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3001\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m     \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m     \u001b[0mi\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m%\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m!=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'str' object is not callable"
     ]
    }
   ],
   "source": [
    "for i in range(1000,3001):\n",
    "    x=1\n",
    "    i=str(i)\n",
    "    for j in str(i):\n",
    "        if int(j)%2!=0:\n",
    "            x=0\n",
    "            break\n",
    "    if x==1:\n",
    "        print(i,end=\" \")\n",
    "print(\"\\b\")\n",
    "#vscode可运行...........可恶\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**13. 输入一个字符串，编程统计字符串中数字和字母的个数并输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "hello world! 123\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "LETTERS 10 DIGITS 3\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world! 123\n",
      "LETTERS 10 DIGITS 3"
     ]
    }
   ],
   "source": [
    "n=input()\n",
    "l=0\n",
    "d=0\n",
    "for i in n:\n",
    "    if i.isalpha():\n",
    "        l=l+1\n",
    "    if i.isdigit():\n",
    "        d=d+1\n",
    "print(\"LETTERS %d\"%l,end=\" \")\n",
    "print(\"DIGITS %d\"%d,end=\"\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**14. 输入一个字符串，编程统计字符串中大写和小写字母的个数并输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "Hello world!\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "UPPER CASE 1 LOWER CASE 9\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n",
      "UPPER CASE 1 LOWER CASE 9"
     ]
    }
   ],
   "source": [
    "n=input()\n",
    "l=0\n",
    "d=0\n",
    "for i in n:\n",
    "    if i.isupper():\n",
    "        l=l+1\n",
    "    if i.islower():\n",
    "        d=d+1\n",
    "print(\"UPPER CASE %d\"%l,end=\" \")\n",
    "print(\"LOWER CASE %d\"%d,end=\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**15. 对于一个输入的数字`a`，编程计算并输出`a+aa+aaa+aaaa`的值。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "9\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "11106\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sum=0\n",
    "a=eval(input())\n",
    "b=a\n",
    "for i in range(4):\n",
    "    sum+=a\n",
    "    a=a*10+b\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**16. 对于一个输入的逗号分隔的整数序列，请使用列表推导式找出列表中的奇数，并以单行逗号分隔的形式输出。**\n",
    "\n",
    ">**提示：**采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "1,2,3,4,5,6,7,8,9\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "1,3,5,7,9\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nm = list(map(int,input().split(\",\")))\n",
    "for i in nm:\n",
    "    if i%2!=0:\n",
    "        print(i,end=\",\")\n",
    "print(\"\\b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**17. 编写程序根据输入的交易日志信息，计算银行账户的净金额。交易信息格式为`D 100 W 200`，`D`表示存款，`W`表示取款。**\n",
    "\n",
    ">**提示：**可以采用`input()`和`while`搭配的形式获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "D 300\n",
    "D 300\n",
    "W 200\n",
    "D 100\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "500\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D 300\n",
      "D 300\n",
      "W 200\n",
      "D 100\n",
      "end\n",
      "500\n"
     ]
    }
   ],
   "source": [
    "ls = []\n",
    "digit = []\n",
    "alpha = []\n",
    "end = 'end'\n",
    "for i in iter(input,end):\n",
    "    ls.append(i.split())\n",
    "for h in ls:\n",
    "    for j in h: \n",
    "        if j.isdigit():\n",
    "            digit.append(j)\n",
    "        if j.isalpha():\n",
    "            alpha.append(j)\n",
    "x =0\n",
    "SUM1 = 0\n",
    "for x in range(0,len(digit)):\n",
    "    if alpha[x]=='D' :\n",
    "        SUM1 = SUM1 + int(digit[x])\n",
    "    elif alpha[x]=='W' :\n",
    "        SUM1 = SUM1 - int(digit[x])\n",
    "    else:\n",
    "        pass\n",
    "print (SUM1)\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**18. 一个网站需要用户输入用户名和密码来完成注册，编写程序来验证用户输入的密码是否有效。判断密码是否有效的标准如下：至少包含一个`[a-z]`的小写字母；至少包含一个`[0-9]`的数字；至少包含一个`[A-Z]`的大写字母；至少包含`[$#@]`中的一个字符；密码长度最小为6，最大为12。程序的输入为一个逗号分隔的密码序列，将符合标准的密码以单行逗号分隔的形式输出。**\n",
    "\n",
    ">**提示：**可以采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "ABd1234@1,a F1#,2w3E*,2We3345\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "ABd1234@1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ABd1234@1,a F1#,2w3E*,2We3345\n",
      "ABd1234@1\n"
     ]
    }
   ],
   "source": [
    "w=[]\n",
    "l=input().split(\",\")\n",
    "for i in l:\n",
    "    d=False\n",
    "    num=False\n",
    "    x=False\n",
    "    en=False\n",
    "    for j in i:\n",
    "        if j.isupper():\n",
    "            d=True\n",
    "        if j.islower():\n",
    "            x=True\n",
    "        if j.isdigit():\n",
    "            num=True\n",
    "        if j in ['$','#','@']:\n",
    "            en=True\n",
    "    if d==True and num==True and x==True and en==True and len(i)>=6 and len(i)<=12:\n",
    "        w.append(i)\n",
    "for x in w:\n",
    "    print(x,end=\",\")\n",
    "print(\"\\b\")\n",
    "    \n",
    "        \n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**19. 编写程序对元组`(name, age, score)`进行升序排序，其中`name`是字符串，`age`和`score`是数值，元组由控制台输入。排序标准如下：根据`name`排序；根据`age`排序；根据`score`排序；排序的优先级是`name>age>score`。**\n",
    "    \n",
    ">**提示：**\n",
    "* 可以采用`input()`和`while`相结合获取输入，给出样例的运行结果。\n",
    "* 可以考虑使用`itemgetter`和`attrgetter`实现。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "Tom,19,80\n",
    "John,20,90\n",
    "Jony,17,91\n",
    "Jony,17,93\n",
    "Json,21,85\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tom,19,80\n",
      "John,20,90\n",
      "Jony,17,91\n",
      "Jony,17,93\n",
      "Json,21,85\n",
      "\n",
      "[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')]\n"
     ]
    }
   ],
   "source": [
    "import operator\n",
    "ls = []\n",
    "while True:\n",
    "    x = input()\n",
    "    if not x:\n",
    "        break\n",
    "    ls.append(tuple(x.split(',')))\n",
    "ls.sort(key=operator.itemgetter(0,2,1))\n",
    "print(ls)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**20. 定义一个带有生成器的类，它可以在给定范围`0`到`n`之间迭代能被7整除的数字。**\n",
    "\n",
    ">**提示：**可以考虑使用`yield`实现。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def putNumbers(n):\n",
    "    i = 0\n",
    "    while i<n:\n",
    "        j=i\n",
    "        i=i+1\n",
    "        if j%7==0:\n",
    "            yield j\n",
    "x= input()\n",
    "for i in putNumbers(int(x)):\n",
    "    print (i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**21. 现在有一个机器人，它从原点`(0, 0)`开始再平面上运动。机器人可以根据给定的步骤上（UP）、下（DOWN）、左（LEFT）、右（RIGHT）移动。例如机器人的运动轨迹是“UP 5 DOWN 3 LEFT 3 RIGHT 2”，方向后面的数字是在该方向上的移动步数。请编写程序计算经过一系列运动后，当前位置距离原点的距离。如果距离是浮点数，那么输出其最接近的整数。**\n",
    "\n",
    ">**提示：**可以采用`input()`和`while`结合获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "UP 5\n",
    "DOWN 3\n",
    "LEFT 3\n",
    "RIGHT 2\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "2\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "UP 5\n",
      "DOWN 3\n",
      "LEFT 3\n",
      "RIGHT 2\n",
      "\n",
      "2.0\n"
     ]
    }
   ],
   "source": [
    "ls = []\n",
    "while True:\n",
    "    n=input()\n",
    "    if not n:\n",
    "        break\n",
    "    ls.append(tuple(n.split(' ')))\n",
    "x=0\n",
    "y=0\n",
    "for j in ls:\n",
    "    i = list(j)\n",
    "    if i[0] == \"UP\":\n",
    "        y +=int(i[1]) \n",
    "    elif i[0] == \"DOWN\":\n",
    "        y +=-int(i[1]) \n",
    "    elif i[0] == \"LEFT\":\n",
    "        x +=-int(i[1]) \n",
    "    elif i[0] == \"RIGHT\":\n",
    "        x +=int(i[1])\n",
    "    else:\n",
    "        print (\"wrong input!\")\n",
    "z=round((x**2+y**2)**1/2,0)\n",
    "print (z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**22. 编写程序统计输入内容中单词出现的频率，输出结果按照字典key的字母数字顺序进行排序。**\n",
    "\n",
    ">**提示：**可以采用`input()`获取输入，给出样例的运行结果。\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "2:2 3.:1 3?:1 New:1 Python:5 Read:1 and:1 between:1 choosing:1 or:2 to:1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**23. 编写程序计算输入数值的平方值。**\n",
    "\n",
    ">**提示：**\n",
    "* 可以采用`input()`获取输入，给出样例的运行结果。\n",
    "* 可以考虑使用运算符`**`\n",
    "\n",
    ">**样例输入：**\n",
    "```python\n",
    "3\n",
    "```\n",
    "\n",
    ">**样例输出：**\n",
    "```python\n",
    "9\n",
    "```                                           "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "n=int(input())\n",
    "print(n**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
